/***********************************************************************************************************
 *** @Author         : jiabao
 *** @Description    :
 *** @Date           : 2024-07-17 13:04:41
 *** @FilePath       : \demo_cc\algorithm\yanghui_triangle\main.cpp
 ***********************************************************************************************************/
#include <iostream>
#include "base_all.h"
using namespace std;

#define RAWS_MAX 100
int main()
{
    u32 rows = 0;
    while (1)
    {
        cout << "Please input how rows yanghui-triangle:(1~100)" << endl;
        cin >> rows;
        if (rows < 1 || rows > 100)
        {
            cout << "Input error,please retry!" << endl;
            base_delayS(2);
            base_sys_cls();
            continue;
        }
        u32 buffArr[RAWS_MAX][RAWS_MAX];

        for (u32 i = 0; i < rows; i++)
        {
            // 开始打印数字前的空格
            for (u32 idx = 1; idx < rows - i; idx++)
            {
                printf("    ");
            }
            for (u32 j = 0; j <= i; j++)
            {
                // 不为每行的第一个和最后一个
                if (j > 0 && j != i)
                {
                    buffArr[i][j] = buffArr[i - 1][j - 1] + buffArr[i - 1][j];
                }
                else
                {
                    buffArr[i][j] = 1;
                }
                printf("%4d    ", buffArr[i][j]);
            }
            printf("\n");
        }
        base_delayS(10);
        base_sys_cls();
    }

    return 0;
}
